#!/bin/sh

echo "* Will extract location of fixed fluxes from FVA file $1 (they will receive value 0)"
echo "* Will extract rays/linealities from rays file $2"

cat $1 | gawk '
BEGIN { seen=0; }
{
if( NF <= 2 ) next;

if( seen != 0 ) printf(" "); 
seen++;

if( $NF == "FIXED" )
	{
	printf("%s", $3);
	}
else printf("?");
}

END { printf("\n"); }
' > mystring

cat mystring $2 | gawk '

(NR==1) {
	numseen=0;
	numvariable=0;
	for( x=1; x<=NF; x++ )
		{
		flux[x] = $x;
		numseen++;
		if( flux[x] == "?" ) numvariable++;
		}
	print "* There were " numseen " fluxes in the top line of which " numvariable " were variable."
	}

(NR>1) {
	pointer=1;
	first=0;

	for(x=1; x<=numseen; x++)
		{
		if( first != 0 ) printf(" ");
		first++;

		if(flux[x] == "?")
			{
			printf("%s", $pointer)
			pointer++;
			}
		else	{
			printf("%s", "0");
			}

		}
	printf("\n");
	# printf("I inserted %d variable fluxes\n",pointer-2);
	}
'


